<template>
	<view class="u-p-20">
		<u-row gutter="16">
			<u-col span="6" v-for="item in collectionList" :key="item.id">
				<view class="goods-item">
					<u-image width="100%" height="300rpx" :src="item.cover_url"></u-image>
					<view class="name u-line-1">{{item.title}}</view>
					<view class="u-flex">
						<view class="price">￥ {{item.price}}</view>
					</view>
				</view>
			</u-col>
		</u-row>
	</view>
</template>

<script>
	const db=uniCloud.database()
	export default {
		data() {
			return {
				collectionList: [], // 收藏数据列表
			}
		},
		created() {
			// const res = await this.$u.api.collects()
			// this.collectionList = res.data
			this.getGoods();
		},
		methods: {
			async getGoods(){
				let res = await db.collection("collection").where({
					user_id:uni.getStorageSync('storage_user')._id
				}).get();
				if(res.result.data.length){
					for(let i in res.result.data){
						let res2 = await db.collection("goods").where({
							_id:res.result.data[i].goods_id
						}).get();
						if(res2.result.data.length){
							this.collectionList =  this.collectionList.concat(res2.result.data);
						}
					}
					
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goods-item {
		padding: 20rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 12rpx 20rpx rgba(0, 0, 0, .1);

		// 标题
		.name {
			font-size: 32rpx;
			font-weight: bold;
			margin-top: 20rpx;
			margin-bottom: 20rpx;
			width: 100%;
		}

		// 价格
		.price {
			width: 100%;
			color: red;
		}
	}
</style>
